﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PdfiumViewer;

namespace PDFium.WindowsFormsApp
{
    /// <summary>
    /// 启动窗体
    /// </summary>
    public partial class FormStartup : Form
    {
        /// <summary>
        /// PDF 预览
        /// </summary>
        private PdfiumViewer.PdfViewer _pdfViewer;

        /// <summary>
        /// 初始化启动窗体
        /// </summary>
        public FormStartup()
        {
            InitializeComponent();

            _pdfViewer = new PdfViewer();
            tableLayoutPanel1.Controls.Add(_pdfViewer);
            _pdfViewer.Dock = DockStyle.Fill;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var doc = PdfiumViewer.PdfDocument.Load("input.pdf");
            _pdfViewer.Renderer.Load(doc);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            using (var doc = PdfiumViewer.PdfDocument.Load("input.pdf"))
            {
                for (int i = 0; i < doc.PageCount; i++)
                {
                    using (var img = doc.Render(i, 300, 300, true))
                    {
                        img.Save($"input_{i}.jpg", ImageFormat.Jpeg);
                    }
                }
            }
        }
    }
}
